import { NotifyService } from '@abp/notify/notify.service';
import { Component, Injector, ViewChild, ViewEncapsulation } from '@angular/core';
import { Http } from '@angular/http';
import { ActivatedRoute } from '@angular/router';
import { AppConsts } from '@shared/AppConsts';
import { appModuleAnimation } from '@shared/animations/routerTransition';
import { AppComponentBase } from '@shared/common/app-component-base';
import { MaterialChargeServiceProxy } from '@shared/service-proxies/service-proxies';
import { FileDownloadService } from '@shared/utils/file-download.service';
import { LazyLoadEvent } from 'primeng/components/common/lazyloadevent';
import { Paginator } from 'primeng/components/paginator/paginator';
import { Table } from 'primeng/components/table/table';
import { EditMaterialModalComponent } from './edit-material-modal.component';

@Component({
  templateUrl: './index.component.html',
  encapsulation: ViewEncapsulation.None,
  animations: [appModuleAnimation()]
})

export class MaterialIndexComponent extends AppComponentBase {
  @ViewChild('editMaterialModal') editMaterialModal: EditMaterialModalComponent;
  @ViewChild('dataTable') dataTable: Table;
  @ViewChild('paginator') paginator: Paginator;

  advancedFiltersAreShown = false;
  filterText = '';
  constructor(
    injector: Injector,
    private _http: Http,
    private _materialServiceProxy: MaterialChargeServiceProxy,
    private _notifyService: NotifyService,
    private _fileDownloadService: FileDownloadService,
  ) {
    super(injector);
  }

  getMaterials(event?: LazyLoadEvent) {
    if (this.primengTableHelper.shouldResetPaging(event)) {
      this.paginator.changePage(0);
      return;
    }

    this.primengTableHelper.showLoadingIndicator();

    this._materialServiceProxy.getMaterialCharges(
      this.filterText,
      1,
      58,
      this.primengTableHelper.getSorting(this.dataTable),
      this.primengTableHelper.getSkipCount(this.paginator, event),
      this.primengTableHelper.getMaxResultCount(this.paginator, event)
    ).subscribe(result => {
      console.log(result.items);
      this.primengTableHelper.totalRecordsCount = result.totalCount;
      this.primengTableHelper.records = result.items;
      this.primengTableHelper.hideLoadingIndicator();
    });
  }


  reloadPage(): void {
    this.paginator.changePage(this.paginator.getPage());
  }

  // returnWl(id: string) {
  //   this.input.materialId = id;
  //   this.message.confirm(
  //     '是否把剩下的物料退还到物流吗？',
  //     this.l('AreYouSure'),
  //     (isConfirmed) => {
  //       if (isConfirmed) {
  //         this._materialServiceProxy.backWl(this.input)
  //           .subscribe(() => {
  //             this.reloadPage();
  //             this.notify.success(this.l('SuccessfullyDeleted'));
  //           });
  //       }
  //     }
  //   );
  // }
}
